//
//  AdvertisingViewController.m
//  TheBankPro
//
//  Created by 吕金状 on 2017/9/26.
//  Copyright © 2017年 dwj. All rights reserved.
//

#import "AdvertisingViewController.h"

@interface AdvertisingViewController ()
{
    NSTimer *timer;
    
}
//@property (nonatomic, assign) int a;
@end

@implementation AdvertisingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.titleImageView];
    [self.view addSubview:self.timeButton];
    timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(test:) userInfo:nil repeats:YES];
    
}
//static int a = 30;
- (void)test:(NSTimer *)timmer{
    _a -- ;
    [self.timeButton setTitle:[NSString stringWithFormat:@"跳过%ld",(long)_a] forState:UIControlStateNormal];
    if (_a == 1) {
        [timmer invalidate];
        if (_getAdvertisingBack) {
            _getAdvertisingBack();
        }
    }
}
#pragma mark - init
- (void)typeButtonClick{
    [timer invalidate];
    if (_getAdvertisingBack) {
        _getAdvertisingBack();
    }
}

- (UIButton *)timeButton{
    if (!_timeButton) {
        _timeButton = [[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 80 / WIDTH_5S_SCALE, 30 / WIDTH_5S_SCALE, 60 / WIDTH_5S_SCALE, 30 / WIDTH_5S_SCALE)];
        _timeButton.titleLabel.font = DEF_FontSize_14;
        _timeButton.backgroundColor = getColor(textColor);
        //        [_timeButton setTitle:@"跳过30" forState:UIControlStateNormal];
        [_timeButton setTitle:[NSString stringWithFormat:@"跳过%d",self.a] forState:UIControlStateNormal];
        [_timeButton setTitleColor:getColor(@"ffffff") forState:UIControlStateNormal];
        [_timeButton addTarget:self action:@selector(typeButtonClick) forControlEvents:UIControlEventTouchUpInside];
        _timeButton.layer.masksToBounds = YES;
        _timeButton.layer.cornerRadius = 15 / WIDTH_5S_SCALE;
    }
    return _timeButton;
}

- (UIImageView *)titleImageView{
    if (!_titleImageView) {
        _titleImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
//        _titleImageView.image = [UIImage imageNamed:@"StartPage1125"];
    }
    return _titleImageView;
}

@end

